<%--
    fileName      : /msgmgmt/msgprdrecom.jsp
    author        : mlw
    createDate    : 2016-05-09  
    lastModifier  : mlw
    lastModifyDate: 2016-05-09       
    description   : 列表页面
--%>
<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8' %>
<%@ taglib uri='ctp-tag' prefix='ctp' %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <title></title>

        <ctp:include items='public,ajaxfileupload,grid,validator,borderlayout,panel,form,button,groupbox,gridlayout,label,textfield,combobox,link,checkboxgroup,checkbox,textarea,datepicker,checkbox,chain,message_ex,ajaxtree'/>

        <script type='text/javascript' kind='variant'>

            var borderlayout1;
            var queryPanel;
            var queryForm;
            var queryGroupbox;    //问题信息
            var queryGridlayout;     
            var msgId; //消息ID
            var prdId; //产品ID
            var msgTitle; //标题
            var msgCont; //内容
            var pushTime; //推送时间
            var deliverNum; //送达数
            var validator5;
            var goBack;		      //返回
            var submit;		      //提交
            var reset;	     	  //重置
            var modify;
  			var modifyData1;
            var modifyURL='';
            var flag;			  //新增修改标识
            var v_msgprdrecomId = "";
            var prdName;
            var prdId;
            var isPublicFlag;
        </script>
        <script type='text/javascript' kind='event'>
	        /*
	         * @method initData
	         * @desc  初始化数据
	         * @author mlw
	         */
			function initData(){
				//setReadOnly(false);
				recomPrd.setReadOnly(true);
				queryPanel1.setTitle('产品查询');
				queryPanel.setTitle('<ctp:label key="add"/>');
				if(flag == 0){//新增
					queryPanel.setTitle('<ctp:label key="add"/>');
				}else if(flag == 1){//修改
					modifyURL = '<ctp:url href="msgprdrecommmain.flowc" flowActionName="querymsgprdrecomdetail"/>';
					queryPanel.setTitle('<ctp:label key="modify"/>');
					   ctp.data.getJSONA({
							url:modifyURL,
							reqData:{"language":"zh_CN","msgId":v_msgprdrecomId},
							
							success:function(data){
								modifyData = data;
								v_msgprdrecomId = modifyData.msgId;
								if(modifyData && modifyData.retCode == "0"){
									setValue('0');
									
								}
							}
					});
				}else{  //查看
					queryForm.getObj("submit").hide();
					queryForm.getObj("reset").hide();
					setReadOnly(true);
					queryPanel.setTitle('<ctp:label key="view"/>');
				}
			}

			/*
	         * @method setReadOnly
	         * @desc  设置表单内容是否readonly
	         * @author mlw
	         */
			function setReadOnly(isReadOnly){
			    queryForm.getObj("msgId").setReadOnly(isReadOnly);
			    queryForm.getObj("prdId").setReadOnly(isReadOnly);
			    queryForm.getObj("msgTitle").setReadOnly(isReadOnly);
			    queryForm.getObj("msgCont").setReadOnly(isReadOnly);
			    queryForm.getObj("pushTime").setReadOnly(isReadOnly);
			    queryForm.getObj("deliverNum").setReadOnly(isReadOnly);
			}

			/*
	         * @method formSucc
	         * @desc  表单提交成功回调函数--提示成功返回列表页面。
	         * @author mlw
	         */
			function formSucc(data){
				  var _message;  
				  if(flag=="0"){ 
					_message='<ctp:label key="add"/>';//新增
				  }else if(flag=="1") {
					_message='<ctp:label key="modify"/>';//修改
				  }  

				  if(data[0].retCode=="0"){//提交成功
					  var mailTo = '';
					  var smtpcontent = '';
					  var subject = '';
					  if(flag == '0'){
						  ctpMSB.confirm({
							  title: '<ctp:label key="tips_msg"/>',
							  message: _message+'<ctp:label key="success_continue_add"/>',
							  cancelTxt: '<ctp:label key="back2list"/>',
							  handler: function(tp){
								  if(tp == 'ok'){
									  window.location.href="<ctp:url href='msgprdrecommmain.flowc' flowActionName='msgprdrecomdetail'/>&flag=0";
								  }else{
									  window.location.href = '<ctp:url href="msgprdrecommmain.flowc" flowActionName="view"/>';
								  }
						      }
						  })
					  }else if(flag == '1'){
	                   ctpMSB.succeed({
	                       title:'<ctp:label key="tips_msg"/>',
	                       closeBtn:true,
	                       message:_message+'<ctp:label key="success"/>',
	                       handler:function(){
								try{
									top.ctpTAB.delTab(top.ctpTAB.getCurrentTabPos());
								}catch(e){
									
								}
						   }
	                       });//操作成功！
					  }
	                 }else{
	              		 var msgErr='<ctp:label key="error_code"/>'+data[0].errorCode+'<ctp:label key="error_msg"/>'+data[0].errorMsg;              
	                     ctpMSB.error({
	                        title:'<ctp:label key="error"/>',
	                        message:_message+''+ msgErr
	                     });//操作失败！
	                }                     
			}
			
			/*
	         * @method submitForm
	         * @desc  提交表单
	         * @author mlw
	         */
			function submitForm(){
			
				 var _mContext = "prodetail.jsp -> queryFormSubmit()";
	        	 try {
	            	 if(flag == 0){
	    		        queryForm.setHiddenValue("flowActionName","addmsgprdrecom");
	               	 }else if(flag == 1){
	               		queryForm.setHiddenValue("flowActionName","editmsgprdrecom");
	               		queryForm.setHiddenValue("msgId",modifyData.msgId);
	                 }
	            	 if(recomPrd.getValue()==""){
	 					alert("请通过查询产品功能输入推荐产品！");
	 					return
	 					}
	            	 if(msgTitle.getValue()==""){
		 				alert("请输入标题！");
		 				msgTitle.focus();
		 				return
		 					}
	            	 if(msgCont.getValue()==""){
		 				alert("请输入内容！");
		 				msgCont.focus();
		 				return
		 					}
	               	queryForm.submit();
	        	 }
	        	 catch (e) {
	                 ctp.core.log.err(_mContext, e.message);
	             }
			}
			/*
	         * @method resetForm
	         * @desc  重置表单
	         * @author mlw
	         */
			function resetForm(){
				ctp.util.closeAllPrompt();//关掉页面上所有验证框架产生的提示框
				if(flag == 0){//新增
					queryForm.reset();
				}else if(flag == 1){//修改
					setValue('1');
				}
			}

			/*
	         * @method setValue
	         * @desc  设置页面值
	         * @author mlw
	         */
			function setValue(isReset){
			
                if(isReset == '1'){
					queryForm.reset();
				}
				//alert(modifyData.prd_flag);
                //queryForm.getObj("msgId").setValue(modifyData.msgId);
                queryForm.getObj("recomPrd").setValue(modifyData.prdName);
                queryForm.getObj("recomPrdId").setValue(modifyData.prdId);
                queryForm.getObj("msgTitle").setValue(modifyData.msgTitle);
                queryForm.getObj("msgCont").setValue(modifyData.msgCont);
                queryForm.getObj("isPublicFlagId").setValue(modifyData.prd_flag);
                queryForm.getObj("pushTime").setValue(modifyData.pushTime);
                //queryForm.getObj("deliverNum").setValue(modifyData.deliverNum);
			}
			/*
	         * @method goBack
	         * @desc 点击返回按钮
	         * @author mlw
	         */
			function goBack(){
				window.location.href = '<ctp:url href="msgprdrecommmain.flowc" flowActionName="view"/>';
			}

			function submitProduct(){//查询产品名称
				if(prdId.getValue()==""&&prdName.getValue()==""){
					alert("必须输入产品名称或者产品代码！");
					return
					}
				queryURL = '<ctp:url href="msgprdrecommmain.flowc" flowActionName="queryproduct"/>';
				   ctp.data.getJSONA({
						url:queryURL,
						reqData:{"prdName":prdName.getValue(),"prdId":prdId.getValue(),"isPublicFlag":isPublicFlag.getValue()},
						success:function(data){
							modifyData1 = data;
						//	alert("13: "+ isPublicFlag.getValue());
							v_msgprdrecomId = modifyData1.msgId;
							var msgproductname =  modifyData1.prdName;
							var msgproductid =  modifyData1.prdId;
							if(modifyData1 && modifyData1.retCode == "0"){
								//setValue('0');							
								recomPrd.setValue(msgproductname);
								recomPrdId.setValue(msgproductid);
								isPublicFlagId.setValue(isPublicFlag.getValue());
							}
						}
				});
				}			
        </script>
		<script type='text/javascript' kind='notUI'>
			var formValidator = new ctp.validator({id:"formValidator"
        	});//验证框架
		</script>
        <script type='text/javascript' kind='ui'>

            $(window).load(function(){
            	v_msgprdrecomId = '<ctp:out name="msgId"/>';
            	flag = '<ctp:out name="flag"/>';
   		     //================================UI变量定义片段============================================================
                

						prdName = new ctp.ui.textfield ({//消息ID
							id : 'prdName' ,
							width:'180px',
							type : 'text'
						});	
					
						prdId = new ctp.ui.textfield ({//产品ID
							id : 'prdId' ,
							width:'180px',
							type : 'text'
						});	

						recomPrd = new ctp.ui.textfield ({//推荐产品名称
							id : 'recomPrd' ,
							width:'180px',
							type : 'text'
						});	

						recomPrdId = new ctp.ui.textfield ({//推荐产品ID
							id : 'recomPrdId' ,
							width:'180px',
							type : 'hidden'
						});	

						isPublicFlagId = new ctp.ui.textfield ({//1.公募/2.私募
							id : 'isPublicFlagId' ,
							width:'180px',
							type : 'hidden'
						});
						
						msgTitle = new ctp.ui.textfield ({//标题
							id : 'msgTitle' ,
							width:'180px',
							type : 'text'
						});	
					
						msgCont = new ctp.ui.textarea ({//内容
							id : 'msgCont' ,
							width:'330px',
							type : 'text'
						});	

						pushTime = new ctp.ui.datepicker({ //推送时间
							id : 'pushTime',
							width:'180px',
							isInput : true,
							showTime :true
						});
						
						isPublicFlag = new ctp.ui.combobox ({//1.公募/2.私募
						       id : 'isPublicFlag' ,
						       width:'180px',
						       defaultItems:[{
						            text:'公募',
						            value:'1',
						            selected:'true'
						           }],
						       items:[
						        {text:'私募',value:'2',title:'私募'}
						       ]
						      }); 
						/* query== new ctp.ui.button({//提交
		                     id:'submit'
		                 }); */
						 queryGridlayout1 = new ctp.ui.gridlayout({
		                     id: 'queryGridlayout1',
		                     width: '1050px',
		                     cols:3,
		                     align: 'center',
		                     height:'0%',
		                     defaults:{
		             			align: 'left',
		             			label: {width: '100px'},
		            			element:{
		            				//默认创建textfield组件
		            				type: 'textfield',
		            				//默认的组件自带属性,width设成'100%'或不传，则该组件和关联标签的宽度之和会占满所在的列
		            				options:{width: '120px'}
		            			}
		                         			
		             		 },
		                                  
		                     items: [
		                             [                                  {
		                                 label: {
		                                     id: 'label0', 
		                                     text: '产品名称', 
		                                     width: '100px'
		                                 }, 
		                                 element: prdName
		                         },                                  {
		                                 label: {
		                                     id: 'label1', 
		                                     text: '产品代码', 
		                                     width: '100px'
		                                 }, 
		                                 element: prdId
		                         },
		                         {
	                                 label: {
	                                     id: 'label2', 
	                                     text: '公募/私募', 
	                                     width: '100px'
	                                 }, 
	                                 element: isPublicFlag
	                         }],                                               
		                	                	
		                            ]
		                 });	                                

                 queryGridlayout = new ctp.ui.gridlayout({
                     id: 'queryGridlayout',
                     width: '1050px',
                     align: 'center',
                     
                     defaults:{
             			align: 'left',
             			label: {width: '100px'},
            			element:{
            				//默认创建textfield组件
            				type: 'textfield',
            				//默认的组件自带属性,width设成'100%'或不传，则该组件和关联标签的宽度之和会占满所在的列
            				options:{width: '120px'}
            			}
                         			
             		 },
                                  
                     items: [
                                     
                        [                                  {
                            label: {
                                id: 'label3', 
                                text: '推荐产品', 
                                width: '100px'                                  
                            }, 
                            element: recomPrd
                    }],          


                        [                                  {
                                label: {
                                    id: 'label4', 
                                    text: '标题', 
                                    width: '100px'
                                }, 
                                element: msgTitle
                        },  ],
                        [                            {
                                label: {
                                    id: 'label5', 
                                    text: '内容', 
                                    width: '100px'
                                }, 
                                element: msgCont
                        }],    
                        [                            {
                            label: {
                                id: 'label6', 
                                text: '推送时间', 
                                width: '100px'
                            }, 
                            element: pushTime
                    }],                                            
                        [                            {
                            label: {
                                id: 'label7', 
                                text: '', 
                                width: '100px'
                            }, 
                            element: recomPrdId
                    },       {
                        label: {
                            id: 'label8', 
                            text: '', 
                            width: '100px'
                        }, 
                        element: isPublicFlagId
                }],   
                            ]
                 });

                queryGroupbox = new ctp.ui.groupbox({
                    id: 'queryGroupbox',
                    items: [
                        queryGridlayout
                    ]
                });

                queryGroupbox1 = new ctp.ui.groupbox({
                    id: 'queryGroupbox1',
                    items: [
                        queryGridlayout1
                    ]
                });
                
                queryForm = new ctp.form({
                    id: 'queryForm',
				    validator:formValidator,
				    width:'98%',
				    postType:'ajax',
				    fixValue:true,			        
				    ajaxPostParam:{success: formSucc} ,
                    items: [
                        queryGroupbox               
                    ],
                    buttons : [{  
	                        id: 'goBack',
	                        text:'<ctp:label key="goBack"/>',
	                        icon: 'return',
	                        onClick: goBack                     
                        },{
	                        id: 'submit',              
	                        text: '<ctp:label key="submit"/>',                  
	                        icon:'apply',
	                        onClick: submitForm 
                 		}, {                                 
	                       id: 'reset',             
	                       text: '<ctp:label key="reset"/>',                   
	                       icon:'reload',
	                       onClick:resetForm
                 	    }]	
                });

                queryForm1 = new ctp.form({
                    id: 'queryForm1',
				    validator:formValidator,
				    width:'98%',
				    postType:'ajax',
				    fixValue:true,			        
				    ajaxPostParam:{success: formSucc} ,
                    items: [
                        queryGroupbox1               
                    ],
                    buttons : [{  
	                        id: 'query',
	                        text:'查询产品',
	                        icon: 'return',
	                        onClick: submitProduct                    
                        }]	
                });
                
                queryPanel = new ctp.ui.panel({
                    id: 'queryPanel',
                    contentPadding :'20px',
                    collapsible:false,
                    items: [
                        queryForm
                    ]
                });

                queryPanel1 = new ctp.ui.panel({
                    id: 'queryPanel1',
                    bodyPadding: 0,
                    collapsible:false,
                    items: [
                        queryForm1
                    ]
                });
                

            
                borderlayout1 = new ctp.ui.borderlayout({
                    type: '2E',
                    north__size: 0.2,
                    north__items:[queryPanel1],
                    center__items:[queryPanel],
                    north__closable:false,
                    north__resizable : true,
                    renderTo: 'body'
                });
                //=========初始化页面数据===============================================
               initData();
              
            });
        </script>
    </head>
    <body>
        <ctp:form name="queryForm" method="post" action="msgprdrecommmain.flowc" flowActionName="">
        <input id="msgId" name="msgId" value="" type="hidden"/>
        </ctp:form>
    </body>
</html>
